package com.jinlejia.erp.ui.mine.pushmoney;

import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.jinlejia.erp.R;
import com.jinlejia.erp.bean.LegendBean;

import net.idik.lib.slimadapter.SlimAdapter;
import net.idik.lib.slimadapter.SlimInjector;
import net.idik.lib.slimadapter.viewinjector.IViewInjector;

import java.util.ArrayList;

public class LegendContentFragment extends Fragment {
    private View view;
    ArrayList<LegendBean> dataList = new ArrayList<>();
    SlimAdapter slimAdapter;

    public LegendContentFragment() {
    }

    public void setData(ArrayList<LegendBean> list) {
        dataList.clear();
        dataList.addAll(list);
        if (dataList.size() > 0)
            slimAdapter.updateData(dataList);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_legend_content, container, false);
        RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler);
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

        slimAdapter = SlimAdapter.create();

        slimAdapter.register(R.layout.item_legend_content, new SlimInjector<LegendBean>() {
            @Override
            public void onInject(final LegendBean data, IViewInjector injector) {
                injector.with(R.id.dot, new IViewInjector.Action() {
                    @Override
                    public void action(View view) {
                        if( dataList.indexOf(data) == 0 ){
                            ((TextView)view).setTextColor(Color.parseColor("#D9564C"));
                        }else if( dataList.indexOf(data) == 1 ){
                            ((TextView)view).setTextColor(Color.parseColor("#FDB52C"));
                        }else if( dataList.indexOf(data) == 2 ){
                            ((TextView)view).setTextColor(Color.parseColor("#2E9C7F"));
                        }else if( dataList.indexOf(data) == 3 ){
                            ((TextView)view).setTextColor(Color.parseColor("#3069A4"));
                        }
                    }
                }).with(R.id.type, new IViewInjector.Action() {
                    @Override
                    public void action(View view) {
                        switch (data.getType()){
                            case "ershoufang":
                                ((TextView)view).setText("二手房");
                                break;
                            case "xinfang":
                                ((TextView)view).setText("一手房");
                                break;
                            case "zulin":
                                ((TextView)view).setText("租房");
                                break;
                            case "jinrong":
                                ((TextView)view).setText("垫资");
                                break;
                            case "person":
                                ((TextView)view).setText("个人提成");
                                break;
                            case "train":
                                ((TextView)view).setText("带训提成");
                                break;
                            case "develop":
                                ((TextView)view).setText("培育提成");
                                break;
                        }
                    }
                })
                        .text(R.id.percent,data.getTypeScale()+"%")
                        .text(R.id.amount,data.getTypeAmount()+"元");
            }
        }).attachTo(recyclerView).updateData(dataList);

        return view;
    }

}
